package com.hnkywl.sts.dao.jhgl;

import com.hnkywl.sts.entity.jhgl.Tpwzjhmx;
import com.hnkywl.sts.entity.sys.Pm;
import net.ruixin.orm.hibernate.SimpleHibernateTemplate;
import org.hibernate.transform.Transformers;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: ZHUCHG
 * Date: 13-4-6
 * Time: 下午5:17
 * To change this template use File | Settings | File Templates.
 */
@Repository
public class TpwzjhmxDao extends SimpleHibernateTemplate<Tpwzjhmx, Long> {
    public List<Map> findPmByTpwzjh(Long id) {
        String sql = "select p.id as \"pm.id\",p.name as \"pm.name\",sum(t.hdsl) as \"hdsl\",'' as \"fkrq\",'0' as \"fkje\" from t_sys_pm p,t_biz_tpwzjhmx t left join t_sys_gg g " +
                " on t.wzgg_id=g.id where p.id=g.pm_id and t.tpwzjh_id=?  group by p.id,p.name";
        return (List<Map>) createSQLQuery(sql, id).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP).list();
    }

    public List<Tpwzjhmx> findTpwzjhmxByTpwzjh(Long id) {
        String hql = "from Tpwzjhmx where tpwzjh.id=?";
        return find(hql, id);
    }
}
